#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/cdev.h>
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/bug.h>			/* For BUG_ON.  */
#include <linux/cpu.h>
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for pr_info() */
#include <linux/module.h> /* Needed by all modules */
#include <linux/delay.h>
#include <linux/smp.h>
#include <linux/kernel_stat.h>
#include <linux/sched.h>
#include <linux/percpu-defs.h>
#include <linux/wait.h>
#include <linux/gpio/driver.h>
#include <linux/atomic.h>
#include <linux/platform_device.h>
#include <linux/poll.h>
#include <linux/kfifo.h>

/**
 *
 *
 *
 my_platform_device003 {
 status = "okay";
 compatible ="my_platform_device_003";
 touch-gpio = <&gpio2 18 IRQ_TYPE_EDGE_FALLING>;
 reset-gpio= <&gpio3 31 GPIO_ACTIVE_HIGH>;
 };

 RK3399 has 5 groups of GPIO banks: GPIO0~GPIO4, and each group is distinguished by numbers A0~A7, B0~B7, C0~C7, D0~D7.


 */

static irqreturn_t key_handler(int irq, void *dev_id) {
	pr_info("key_handler \n");
	return IRQ_HANDLED;
}

int myprobe(struct platform_device *pdev) {
	int ret;
	int irq_pin;
	int irq_flags;
	int irq;
	struct device_node *np = pdev->dev.of_node;

	irq_pin = of_get_named_gpio_flags(np, "touch-gpio", 0,
			(enum of_gpio_flags*) (&irq_flags));
	if (irq_pin < 0) {
		pr_err("of_get_named_gpio_flags failed \n");
		return irq_pin;
	}

	irq = gpio_to_irq(irq_pin);

	pr_info("irq_flags:%d\n", irq_flags);

	ret = devm_request_irq(&pdev->dev, irq, key_handler, irq_flags,
			"my_key_driver",
			NULL);

	if (ret < 0) {
		pr_err("request_irq failed \n");
		return ret;
	}
	return 0;
}

int myremove(struct platform_device *pdev) {
	pr_info("myplatformdriver myremove \n");
	return 0;
}

struct of_device_id my_of_match_table =
		{ .compatible = "my_platform_device_003", };

struct platform_driver my_platform_driver = { .driver =
		{ .of_match_table = &my_of_match_table, .name = "my-platform-driver",
				.owner = THIS_MODULE, }, .probe = myprobe, .remove = myremove, };

module_platform_driver(my_platform_driver);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andy");
MODULE_DESCRIPTION("andy one-key driver");
MODULE_ALIAS("one-key");
